package br.pucrs.lognplay.repository.mapper.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import br.pucrs.lognplay.entity.Tag;
import br.pucrs.lognplay.repository.RepositoryException;
import br.pucrs.lognplay.repository.TagRepository;

public class TagMapper extends GenericMapper<Tag, String> implements TagRepository {

	public TagMapper() {
		super();
	}

	public TagMapper(EntityManager entityManager) {
		super(entityManager);
	}

	public List<Tag> listByClientId(String clientId) throws RepositoryException {
		try {
			TypedQuery<Tag> typedQuery = getEntityManager().createQuery("SELECT tag FROM Tag tag WHERE tag.client.id = :clientId", Tag.class);
			typedQuery.setParameter("clientId", clientId);
			return typedQuery.getResultList();
		} catch (Exception e) {
			throw new RepositoryException("Error on list tags by client id", e);
		}
	}
}
